﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace SharpShare.Management.Data {
    [DataContract]
    public sealed class SessionInfo {
        public SessionInfo(string identifier, string service, string user) {
            this.Identifier = identifier;
            this.Service = service;
            this.User = user;
            this.OpenFiles = new List<OpenFileInfo>();
        }

        [Browsable(false)]
        [DataMember]
        public string Identifier { get; private set; }

        [DataMember]
        public DateTime Date { get; set; }

        [DataMember]
        public string Service { get; private set; }

        [DataMember]
        public string User { get; private set; }

        [Browsable(false)]
        [DataMember]
        public IList<OpenFileInfo> OpenFiles { get; private set; }

        [DisplayName("# Open Files")]
        public int OpenFileCount {
            get {
                return this.OpenFiles.Count;
            }
        }

        [DisplayName("Name")]
        public string Username {
            get {
                return this.User;
            }
        }

        [DisplayName("Connected Time")]
        [TypeConverter(typeof(TimeSpanConverter))]
        public TimeSpan ConnectedTime {
            get {
                return (DateTime.Now - this.Date);
            }
        }
    }
}
